/********************************************************
Code to create the predicted probabilities for Figure 4
using the Pew CNN Data. Also creates the Table for these reults. 
Plotting is done using R. 
***********************************************************/


/*************************************
Pew/CNN
**************************************/

/**************************
		Data
**************************/

clear
*change directory to "....\Data\"
*cd 
use "pew_cnn_comb.dta"

/**************************
		Cleaning
Some of the labels are not right 
**************************/

**Income
label def inc1 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000-99,999" 5 "100,000+"
label values income1 inc1
label var income1 "Income"

label def inc2 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000+"
label values income2 inc2
label var income2 "Income"

**Gender
label def gend 1 "Female" 0 "Male"
label values gender gend
label var gender "Gender"

**Education 
label var educ "Education"
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "Post-BA"
label values educ edu

**Race/Ethnicity
*Remove the 9
recode race_eth (9 = .)
label var race_eth "Race/Ethnicity"
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Other Race"
label values race_eth rac

**Age
label var age "Age"

**Sponsor
encode sponsor, gen(sponsor1)

**Year
label var year "Year of Survey"

**Too Extreme
label var too_extreme1 "Parties Too Extreme?"
label def too1 1 "Neither" 2 "One Too Extreme" 3 "Both Too Extreme"
label values too_extreme1  too1

***PID & Ideol Ext
label var pid_ext "PID Extremity"
label def pext 1 "Independent" 2 "Leaner" 3 "Partisan"
label values pid_ext pext

label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Liberal/Conservative" 3 "Very Liberal/Conservative"
label values ideol_ext iext


/**************************
	Model and Predictions
**************************/

eststo clear
eststo: gsem (i.too_extreme1 <- i.pid_ext##i.ideol_ext i.gender i.race_eth c.age i.income1 i.educ year sponsor1 S[surveyid]@1) [pweight=weight], mlogit
	*Margins to plot
	margins, at(pid_ext=(1 3) ideol_ext=(1(1)3)) saving(pewcnn_probs_alt, replace)
	
*Table
esttab using "table_oa6.rtf", replace onecell se aic bic label nobaselevels unstack b(3) ///
	mtitles("Neither" "One Party" "Both Parties") ///
	title("{\b Table OA6:} Partisanship x Ideology Interaction (Pew & CNN)")
	

eststo clear

/******************************************************************
	Lucid
******************************************************************/

clear
use "lucid_coded_all.dta"
set more off 


/**************************
		Cleaning
Some of the labels are not right 
**************************/

****PID Strength/Extremity
label var pid_idstr_1 "PID ID Strength"


****Ideology
*Symbolic
label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Closer Lib/Con"  3 "Somewhat Lib/Con" 4 "Very Lib/Con"
label values ideol_ext iext

****Issue Consistency
label var op_ideol_cons "Issue Consistency"

*Operational
label var op_ideol "Operational Ideology"

****Political Knowledge
label var knowl_sum "Political Knowledge"

****Opinionation
label var opinionation "Opinionation"

****Demographics
*Age
label var age "Age"

*Gender
label var gender "Gender"

*Race
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Asian" 5 "Other Race"
label values race_eth rac
label var race_eth "Race/Ethnicity"

*Education
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "BA+"
label values educ edu

*Income
label var house_income "Income"

*Weight
label var weight "Raked Survey Weight"

*Too Extreme
label var too_extreme_1 "Parties Too Extreme?"
label def tooext 1 "Neither Party" 2 "One Party" 3 "Both Parties"
label values too_extreme_1 tooext

*Perceived Policy Alienation/Distance
gen ppd = abs(abs(self_ideol-dem_ideol)-abs(self_ideol-rep_ideol))
label var ppd "Perceived Policy Distance"


********************/

***Unweighted: PID Strength*Extremity
eststo clear
eststo: mlogit too_extreme_1 c.pid_idstr_all##i.ideol_ext op_ideol_cons ppd knowl_sum opinionation c.age  house_income i.gender i.race_eth i.educ , base(1)
		
		*Probabilities
		margins, at(pid_idstr_all=(1 4) ideol_ext=(1(1)4)) saving(lucid_probs_ideolext, replace)
		
*Table
esttab using "table_oa7.rtf", replace onecell se bic label nobaselevels unstack ///
	title("{\b Table OA7:} Party x Ideology Interaction (Lucid; Ideological Extremity Model)") pr2
	
***Unweighted: PID Strength*Operational Ideology
eststo clear
eststo: mlogit too_extreme_1 c.pid_idstr_all##c.op_ideol_cons i.ideol_ext ppd knowl_sum opinionation c.age house_income i.gender i.race_eth i.educ , base(1)
		
		*Probabilities
		margins, at(pid_idstr_all=(1 4) op_ideol_cons=(0(1)5)) saving(lucid_probs_op_ideol_cons, replace)
		
*Table
esttab using "table_oa8.rtf", replace onecell se aic bic label nobaselevels unstack ///
	title("{\b Table OA8:} Is the Party Sytem Too Extreme? (Lucid; Operational Ideology Model)") pr2
	
***Unweighted: PID Strength*Operational Ideology
eststo clear
eststo: mlogit too_extreme_1 c.pid_idstr_all##c.ppd c.op_ideol_cons i.ideol_ext  knowl_sum opinionation c.age house_income i.gender i.race_eth i.educ , base(1)
		
		*Probabilities
		margins, at(pid_idstr_all=(1 4) ppd=(0(1)6)) saving(lucid_probs_ppd, replace)
		
*Table
esttab using "table_oa9.rtf", replace onecell se aic bic label nobaselevels unstack ///
	title("{\b Table OA9:} Party x Ideology Interaction (Lucid; PPD Model)") pr2
		